package com.example.print.util;

import android.graphics.Bitmap;
import android.graphics.Canvas;
import android.graphics.Color;
import android.graphics.Paint;
import android.graphics.Rect;
import android.graphics.Matrix;

import android.os.Environment;

import com.google.zxing.BarcodeFormat;
import com.google.zxing.EncodeHintType;
import com.google.zxing.MultiFormatWriter;
import com.google.zxing.common.BitMatrix;
import com.google.zxing.qrcode.decoder.ErrorCorrectionLevel;

import java.util.Hashtable;
import java.util.List;
import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;

/**
 * Created by moxiaomo
 * on 2020/7/21
 */
public class QRCodeUtil {

    private static final String CHARSET="UTF-8";
    private static final String FORMAT_NAME="JPG";
    // 二维码尺寸
    private static final int QRCODE_SIZE=314;
    // LOGO宽度
    private static final int WIDTH=60;
    // LOGO高度
    private static final int HEIGHT=60;

    private static boolean isSave = true;

    /**
     * user: Rex
     * date: 2016年12月29日  上午12:31:29
     *
     * @param content 二维码内容
     * @return 返回二维码图片
     */
    public static Bitmap createImage(String content,int heights,int widths) {
        Hashtable<EncodeHintType, Object> hints=new Hashtable<> ();
        hints.put (EncodeHintType.ERROR_CORRECTION, ErrorCorrectionLevel.H);
        hints.put (EncodeHintType.CHARACTER_SET, CHARSET);
        hints.put (EncodeHintType.MARGIN, 2);
        BitMatrix bitMatrix=null;
        Bitmap image=null;
        try {
            bitMatrix=new MultiFormatWriter ().encode (content, BarcodeFormat.QR_CODE, widths, heights, hints);
            int width=bitMatrix.getWidth ();
            int height=bitMatrix.getHeight ();
            int[] pixels=new int[width * height];
            for (int x=0; x < width; x++) {
                for (int y=0; y < height; y++) {
                    if (bitMatrix.get (y, x)) {
                        pixels[y * width + x]=0xff000000;
                    } else {
                        pixels[y * width + x]=0xffffffff;
                    }
//                    image.setPixel(x, y, bitMatrix.get(x, y) ? 0xFF000000 : 0xFFFFFFFF);
                }
            }
            image=Bitmap.createBitmap (pixels, width, height, Bitmap.Config.ARGB_8888);
        } catch (Exception e) {
            e.printStackTrace ();
        }
        // 插入图片
//        QRCodeUtil.insertImage(image, logoImgPath, needCompress);
        return image;
    }

    /**
     * 生成图片  加上title的图片
     *
     * @param content
     * @param title
     * @return
     */
    public static Bitmap createImage(String content, String title) {
        int picWidth=720;//生成图片的宽度
        int picHeight=765;//生成图片的高度
        int titleTextSize=30;
        int contentTextSize=22;
        int textColor=Color.BLACK;
        int qrWidth=366;
        int qrHeight=366;
        int paddingTop=152;
        int paddingMiddle=40;
        int paddingBottom=24;

        //最终生成的图片
        Bitmap result=Bitmap.createBitmap (picWidth, picHeight, Bitmap.Config.ARGB_8888);

        Paint paint=new Paint ();
        paint.setColor (Color.WHITE);
        Canvas canvas=new Canvas (result);

        //先画一整块白色矩形块
        canvas.drawRect (0, 0, picWidth, picHeight, paint);

        //画title文字
        Rect bounds=new Rect ();
        paint.setColor (textColor);
        paint.setTextSize (titleTextSize);
        //获取文字的字宽高，以便将文字与图片中心对齐
        paint.getTextBounds (title, 0, title.length (), bounds);
        canvas.drawText (title, picWidth / 2 - bounds.width () / 2, paddingTop + bounds.height () / 2, paint);

        //画白色矩形块
        int qrTop=paddingTop + titleTextSize + paddingMiddle;//二维码的顶部高度

        //画二维码
        Hashtable<EncodeHintType, Object> hints=new Hashtable<> ();
        hints.put (EncodeHintType.ERROR_CORRECTION, ErrorCorrectionLevel.H);
        hints.put (EncodeHintType.CHARACTER_SET, CHARSET);
        hints.put (EncodeHintType.MARGIN, 5);
        BitMatrix bitMatrix;
        Bitmap image=null;
        try {
            bitMatrix=new MultiFormatWriter ().encode (content, BarcodeFormat.QR_CODE, qrWidth, qrHeight, hints);
            int width=bitMatrix.getWidth ();
            int height=bitMatrix.getHeight ();
            image=Bitmap.createBitmap (width, height, Bitmap.Config.ARGB_8888);
            for (int x=0; x < width; x++) {
                for (int y=0; y < height; y++) {
                    image.setPixel (x, y, bitMatrix.get (x, y) ? 0xFF000000 : 0xFFFFFFFF);
                }
            }
        } catch (Exception e) {
            e.printStackTrace ();
        }

        paint.setColor (Color.BLACK);
        canvas.drawBitmap (image, (picWidth - qrWidth) / 2, qrTop, paint);

        //画文字
        paint.setColor (Color.BLACK);
        paint.setTextSize (contentTextSize);
        int lineTextCount=(int) ((picWidth - 50) / contentTextSize);
        int line=(int) (Math.ceil (Double.valueOf (content.length ()) / Double.valueOf (lineTextCount)));
        int textTop=qrTop + qrHeight + paddingBottom;//地址的顶部高度

        for (int i=0; i < line; i++) {
            String s;
            if (i == line - 1) {
                s=content.substring (i * lineTextCount, content.length ());
            } else {
                s=content.substring (i * lineTextCount, (i + 1) * lineTextCount);
            }
            paint.getTextBounds (content, 0, s.length (), bounds);

            canvas.drawText (s, picWidth / 2 - bounds.width () / 2, textTop + i * contentTextSize + i * 5 + bounds.height () / 2, paint);
        }

        canvas.save ();
        canvas.restore ();

        return result;
    }


    /**
     * 生成图片  加上title的图片
     *
     * @param content
     * @param list
     * @return
     */
    public static Bitmap createImage2(String content, List<String> list) {
        int picWidth=384;//生成图片的宽度
        int picHeight=200;//生成图片的高度
        int titleTextSize=20;
        int textColor=Color.BLACK;
        int qrWidth=200;
        int qrHeight=200;
        int paddingTop=10;
        int textX = 160;
        int textY = 50;

        //最终生成的图片
        Bitmap result=Bitmap.createBitmap (picWidth, picHeight, Bitmap.Config.ARGB_8888);

        Paint paint=new Paint ();
        paint.setColor (Color.WHITE);
        Canvas canvas=new Canvas (result);

        //先画一整块白色矩形块
        canvas.drawRect (0, 0, picWidth, picHeight, paint);

        //画title文字
        Rect bounds=new Rect ();
        paint.setColor (textColor);
        paint.setTextSize (titleTextSize);
        for (int i=0; i < list.size (); i++) {
            //获取文字的字宽高，以便将文字与图片中心对齐
            paint.getTextBounds (list.get (i), 0, list.get (i).length (), bounds);
            canvas.drawText (list.get (i), textX, textY, paint);
            textY+=30;
        }

        //画白色矩形块
        int qrTop=paddingTop;//二维码的顶部高度

        //画二维码
        Hashtable<EncodeHintType, Object> hints=new Hashtable<> ();
        hints.put (EncodeHintType.ERROR_CORRECTION, ErrorCorrectionLevel.H);
        hints.put (EncodeHintType.CHARACTER_SET, CHARSET);
        hints.put (EncodeHintType.MARGIN, 5);
        BitMatrix bitMatrix;
        Bitmap image=null;
        try {
            bitMatrix=new MultiFormatWriter ().encode (content, BarcodeFormat.QR_CODE, qrWidth, qrHeight, hints);
            int width=bitMatrix.getWidth ();
            int height=bitMatrix.getHeight ();
            image=Bitmap.createBitmap (width, height, Bitmap.Config.ARGB_8888);
            for (int x=0; x < width; x++) {
                for (int y=0; y < height; y++) {
                    image.setPixel (x, y, bitMatrix.get (x, y) ? 0xFF000000 : 0xFFFFFFFF);
                }
            }
        } catch (Exception e) {
            e.printStackTrace ();
        }

        paint.setColor (Color.BLACK);
        canvas.drawBitmap (image, -40, qrTop, paint);

        //画文字
//        paint.setColor (Color.BLACK);
//        paint.setTextSize (contentTextSize);
//        int lineTextCount=(int) ((picWidth - 50) / contentTextSize);
//        int line=(int) (Math.ceil (Double.valueOf (content.length ()) / Double.valueOf (lineTextCount)));
//        int textTop=qrTop + qrHeight + paddingBottom;//地址的顶部高度
//
//        for (int i=0; i < line; i++) {
//            String s;
//            if (i == line - 1) {
//                s=content.substring (i * lineTextCount, content.length ());
//            } else {
//                s=content.substring (i * lineTextCount, (i + 1) * lineTextCount);
//            }
//            paint.getTextBounds (content, 0, s.length (), bounds);
//
//            canvas.drawText (s, picWidth / 2 - bounds.width () / 2, textTop + i * contentTextSize + i * 5 + bounds.height () / 2, paint);
//        }

        canvas.save ();
        canvas.restore ();
        return result;
    }

    /**
     * 生成图片  加上title的图片
     *
     * @param text
     * @return
     */
    public static Bitmap createImage3(String text) {
        int picWidth=500;//生成图片的宽度
        int picHeight=220;//生成图片的高度
        int titleTextSize=25;
        int textColor=Color.BLACK;
        int qrWidth=160;
        int qrHeight=160;
        int paddingTop=0;
        int textX = 100;
        int textY = 200;

        //最终生成的图片
        Bitmap result=Bitmap.createBitmap (picWidth, picHeight, Bitmap.Config.ARGB_8888);

        Paint paint=new Paint ();
        paint.setColor (Color.WHITE);
        Canvas canvas=new Canvas (result);

        //先画一整块白色矩形块
        canvas.drawRect (0, 0, picWidth, picHeight, paint);

        //画title文字
        paint.setColor (textColor);
        paint.setTextSize (titleTextSize);
        paint.setTextAlign(Paint.Align.CENTER);
        float textWidth = paint.measureText(text);
        textX = (picWidth -120) / 2 - (int) (textWidth / 2);
        canvas.drawText (text, textX, textY, paint);

        //画白色矩形块
        int qrTop=paddingTop;//二维码的顶部高度

        //画二维码
        Hashtable<EncodeHintType, Object> hints=new Hashtable<> ();
        hints.put (EncodeHintType.ERROR_CORRECTION, ErrorCorrectionLevel.H);
        hints.put (EncodeHintType.CHARACTER_SET, CHARSET);
        hints.put (EncodeHintType.MARGIN, 0);
        BitMatrix bitMatrix;
        Bitmap image=null;
        try {
            bitMatrix=new MultiFormatWriter ().encode (text, BarcodeFormat.QR_CODE, qrWidth, qrHeight, hints);
            int width=bitMatrix.getWidth ();
            int height=bitMatrix.getHeight ();
            image=Bitmap.createBitmap (width, height, Bitmap.Config.ARGB_8888);
            for (int x=0; x < width; x++) {
                for (int y=0; y < height; y++) {
                    image.setPixel (x, y, bitMatrix.get (x, y) ? 0xFF000000 : 0xFFFFFFFF);
                }
            }
        } catch (Exception e) {
            e.printStackTrace ();
        }

        paint.setColor (Color.BLACK);
        canvas.drawBitmap (image, 120, qrTop, paint);
        canvas.save ();
        canvas.restore ();
        return result;
    }

    /**
         * 生成图片  加上title的图片
         *
         * @param qrcode
         * @param vendor
         * @param specification
         * @param weight
         * @return
         */

        public static Bitmap wirerodpurchaseinorder(String qrcode,String vendor,String specification,String weight,String name) {
            int picWidth=350;//生成图片的宽度
            int picHeight=280;//生成图片的高度
            int titleTextSize=25;
            int textColor=Color.BLACK;
            int qrWidth=150;
            int qrHeight=150;
            int paddingTop=40;

            //最终生成的图片
            Bitmap result=Bitmap.createBitmap (picWidth, picHeight, Bitmap.Config.ARGB_8888);

            Paint paint=new Paint ();
            paint.setColor (Color.WHITE);
            Canvas canvas=new Canvas (result);

            //先画一整块白色矩形块
            canvas.drawRect (0, 0, picWidth, picHeight, paint);

            //画title文字
            paint.setColor (textColor);
            paint.setTextSize (titleTextSize);
            paint.setFakeBoldText(true);
            canvas.drawText ("厂家: "+vendor, 165, 70, paint);
            canvas.drawText ("规格: "+specification, 165, 120, paint);
            canvas.drawText ("重量: "+weight+"T", 165, 170, paint);
            canvas.drawText (qrcode, 0, 220, paint);
            canvas.drawText (name, 0, 250, paint);

            //画白色矩形块
            int qrTop=paddingTop;//二维码的顶部高度

            //画二维码
            Hashtable<EncodeHintType, Object> hints=new Hashtable<> ();
            hints.put (EncodeHintType.ERROR_CORRECTION, ErrorCorrectionLevel.H);
            hints.put (EncodeHintType.CHARACTER_SET, CHARSET);
            hints.put (EncodeHintType.MARGIN, 0);
            BitMatrix bitMatrix;
            Bitmap image=null;
            try {
                bitMatrix=new MultiFormatWriter ().encode (qrcode, BarcodeFormat.QR_CODE, qrWidth, qrHeight, hints);
                int width=bitMatrix.getWidth ();
                int height=bitMatrix.getHeight ();
                image=Bitmap.createBitmap (width, height, Bitmap.Config.ARGB_8888);
                for (int x=0; x < width; x++) {
                    for (int y=0; y < height; y++) {
                        image.setPixel (x, y, bitMatrix.get (x, y) ? 0xFF000000 : 0xFFFFFFFF);
                    }
                }
            } catch (Exception e) {
                e.printStackTrace ();
            }

            paint.setColor (Color.BLACK);
            canvas.drawBitmap (image, 0, qrTop, paint);
            canvas.save ();
            canvas.restore ();
            return result;
        }

        public static Bitmap acidTakeup(String qrcode,String steel,String specification,String weight) {
            int picWidth=350;//生成图片的宽度
            int picHeight=280;//生成图片的高度
            int titleTextSize=25;
            int textColor=Color.BLACK;
            int qrWidth=150;
            int qrHeight=150;
            int paddingTop=40;

            //最终生成的图片
            Bitmap result=Bitmap.createBitmap (picWidth, picHeight, Bitmap.Config.ARGB_8888);

            Paint paint=new Paint ();
            paint.setColor (Color.WHITE);
            Canvas canvas=new Canvas (result);

            //先画一整块白色矩形块
            canvas.drawRect (0, 0, picWidth, picHeight, paint);

            //画title文字
            paint.setColor (textColor);
            paint.setTextSize (titleTextSize);
            paint.setFakeBoldText(true);
            canvas.drawText ("钢号: "+steel, 165, 70, paint);
            canvas.drawText ("规格: "+specification, 165, 120, paint);
            canvas.drawText ("重量: "+weight+"T", 165, 170, paint);
            canvas.drawText (qrcode, 0, 240, paint);

            //画白色矩形块
            int qrTop=paddingTop;//二维码的顶部高度

            //画二维码
            Hashtable<EncodeHintType, Object> hints=new Hashtable<> ();
            hints.put (EncodeHintType.ERROR_CORRECTION, ErrorCorrectionLevel.H);
            hints.put (EncodeHintType.CHARACTER_SET, CHARSET);
            hints.put (EncodeHintType.MARGIN, 0);
            BitMatrix bitMatrix;
            Bitmap image=null;
            try {
                bitMatrix=new MultiFormatWriter ().encode (qrcode, BarcodeFormat.QR_CODE, qrWidth, qrHeight, hints);
                int width=bitMatrix.getWidth ();
                int height=bitMatrix.getHeight ();
                image=Bitmap.createBitmap (width, height, Bitmap.Config.ARGB_8888);
                for (int x=0; x < width; x++) {
                    for (int y=0; y < height; y++) {
                        image.setPixel (x, y, bitMatrix.get (x, y) ? 0xFF000000 : 0xFFFFFFFF);
                    }
                }
            } catch (Exception e) {
                e.printStackTrace ();
            }

            paint.setColor (Color.BLACK);
            canvas.drawBitmap (image, 0, qrTop, paint);
            canvas.save ();
            canvas.restore ();
            return result;
        }

        public static Bitmap wireProductback(String qrcode,String name,String specification,String weight) {
            int picWidth=350;//生成图片的宽度
            int picHeight=280;//生成图片的高度
            int titleTextSize=25;
            int textColor=Color.BLACK;
            int qrWidth=150;
            int qrHeight=150;
            int paddingTop=40;

            //最终生成的图片
            Bitmap result=Bitmap.createBitmap (picWidth, picHeight, Bitmap.Config.ARGB_8888);

            Paint paint=new Paint ();
            paint.setColor (Color.WHITE);
            Canvas canvas=new Canvas (result);

            //先画一整块白色矩形块
            canvas.drawRect (0, 0, picWidth, picHeight, paint);

            //画title文字
            paint.setColor (textColor);
            paint.setTextSize (titleTextSize);
            paint.setFakeBoldText(true);
            canvas.drawText ("名称: "+name, 165, 70, paint);
            canvas.drawText ("规格: "+specification, 165, 120, paint);
            canvas.drawText ("重量: "+weight+"T", 165, 170, paint);
            canvas.drawText (qrcode, 0, 240, paint);

            //画白色矩形块
            int qrTop=paddingTop;//二维码的顶部高度

            //画二维码
            Hashtable<EncodeHintType, Object> hints=new Hashtable<> ();
            hints.put (EncodeHintType.ERROR_CORRECTION, ErrorCorrectionLevel.H);
            hints.put (EncodeHintType.CHARACTER_SET, CHARSET);
            hints.put (EncodeHintType.MARGIN, 0);
            BitMatrix bitMatrix;
            Bitmap image=null;
            try {
                bitMatrix=new MultiFormatWriter ().encode (qrcode, BarcodeFormat.QR_CODE, qrWidth, qrHeight, hints);
                int width=bitMatrix.getWidth ();
                int height=bitMatrix.getHeight ();
                image=Bitmap.createBitmap (width, height, Bitmap.Config.ARGB_8888);
                for (int x=0; x < width; x++) {
                    for (int y=0; y < height; y++) {
                        image.setPixel (x, y, bitMatrix.get (x, y) ? 0xFF000000 : 0xFFFFFFFF);
                    }
                }
            } catch (Exception e) {
                e.printStackTrace ();
            }

            paint.setColor (Color.BLACK);
            canvas.drawBitmap (image, 0, qrTop, paint);
            canvas.save ();
            canvas.restore ();
            return result;
        }

        public static Bitmap silkTakeup(String number,String name,String specification,String steel,String length,String weight,String kh,String pcd,String user) {
            int picWidth=380;//生成图片的宽度
            int picHeight=280;//生成图片的高度
            int titleTextSize=24;
            int textColor=Color.BLACK;
            int qrWidth=180;
            int qrHeight=180;
            int paddingTop=80;

            //最终生成的图片
            Bitmap result = Bitmap.createBitmap(picWidth, picHeight, Bitmap.Config.ARGB_8888);

            Paint paint = new Paint();
            paint.setColor(Color.WHITE);
            Canvas canvas = new Canvas(result);

            //先画一整块白色矩形块
            canvas.drawRect(0, 0, picWidth, picHeight, paint);

            //        canvas.rotate(-90, 260, 260);

            //画白色矩形块

            paint.setColor(textColor);
            paint.setTextSize(titleTextSize);
            paint.setFakeBoldText(true);

            //画二维码
            Bitmap bitmap = BitmapUtils.encode2dAsBitmap(number, BarcodeFormat.QR_CODE, qrWidth, qrHeight);

            canvas.drawBitmap(bitmap, 0, -25, paint);

            //画title文字

            canvas.drawText("名称 " + name, 160, 30, paint);
            canvas.drawText("规格  " + specification + " mm", 160, 60, paint);
            canvas.drawText("钢号  " + steel + " ", 160, 90, paint);
            canvas.drawText("米长  " + length +" m", 160, 120, paint);
            canvas.drawText("净重  " + weight +" T", 160, 150, paint);
            paint.setTextSize(22);
            canvas.drawText("排产单号：" + pcd + "", 25, 180, paint);
            canvas.drawText("客户 " + kh + "", 25, 210, paint);
            canvas.drawText(""+number + "  " + user, 25, 240, paint);
            paint.setTextSize(22);
            canvas.save();
            canvas.restore();
            saveBitmap(result);
            return result;
        }


        public static Bitmap heatTakeup(String number,String name,String specification,String steel,String weight,String kh,String pcd,String qd,String zinc) {
            int picWidth=380;//生成图片的宽度
            int picHeight=280;//生成图片的高度
            int titleTextSize=24;
            int textColor=Color.BLACK;
            int qrWidth=180;
            int qrHeight=180;
            int paddingTop=80;

            //最终生成的图片
            Bitmap result = Bitmap.createBitmap(picWidth, picHeight, Bitmap.Config.ARGB_8888);

            Paint paint = new Paint();
            paint.setColor(Color.WHITE);
            Canvas canvas = new Canvas(result);

            //先画一整块白色矩形块
            canvas.drawRect(0, 0, picWidth, picHeight, paint);

            //        canvas.rotate(-90, 260, 260);

            //画白色矩形块

            paint.setColor(textColor);
            paint.setTextSize(titleTextSize);
            paint.setFakeBoldText(true);

            //画二维码
            Bitmap bitmap = BitmapUtils.encode2dAsBitmap(number, BarcodeFormat.QR_CODE, qrWidth, qrHeight);

            canvas.drawBitmap(bitmap, 0, -25, paint);

            //画title文字

            canvas.drawText("名称 " + name, 160, 30, paint);
            canvas.drawText("规格  " + specification + " mm", 160, 60, paint);
            canvas.drawText("钢号  " + steel + " ", 160, 90, paint);
            canvas.drawText("净重  " + weight +" T", 160, 120, paint);
            paint.setTextSize(22);
            canvas.drawText("抗拉强度：" + qd + " MPa", 25, 150, paint);
            canvas.drawText("上锌量：" + zinc + " g/㎡", 25, 180, paint);
            canvas.drawText("排产单号 " + pcd + "", 25, 210, paint);
            canvas.drawText(""+number, 25, 240, paint);
            paint.setTextSize(22);
            canvas.save();
            canvas.restore();
            saveBitmap(result);
            return result;
        }



        public static Bitmap gjxtwistwireTakeup(String number,String name,String specification,String steel,String length,String weight,String kh,String pcd,String user) {
            int picWidth=380;//生成图片的宽度
            int picHeight=280;//生成图片的高度
            int titleTextSize=24;
            int textColor=Color.BLACK;
            int qrWidth=180;
            int qrHeight=180;
            int paddingTop=80;

            //最终生成的图片
            Bitmap result = Bitmap.createBitmap(picWidth, picHeight, Bitmap.Config.ARGB_8888);

            Paint paint = new Paint();
            paint.setColor(Color.WHITE);
            Canvas canvas = new Canvas(result);

            //先画一整块白色矩形块
            canvas.drawRect(0, 0, picWidth, picHeight, paint);

            //        canvas.rotate(-90, 260, 260);

            //画白色矩形块

            paint.setColor(textColor);
            paint.setTextSize(titleTextSize);
            paint.setFakeBoldText(true);

            //画二维码
            Bitmap bitmap = BitmapUtils.encode2dAsBitmap(number, BarcodeFormat.QR_CODE, qrWidth, qrHeight);

            canvas.drawBitmap(bitmap, 0, -25, paint);

            //画title文字

            canvas.drawText("名称 " + name, 160, 30, paint);
            canvas.drawText("规格  " + specification + " mm", 160, 60, paint);
            canvas.drawText("钢号  " + steel + " ", 160, 90, paint);
            canvas.drawText("米长  " + length +" m", 160, 120, paint);
            canvas.drawText("净重  " + weight +" T", 160, 150, paint);
            paint.setTextSize(22);
            canvas.drawText("排产单号：" + pcd + "", 25, 180, paint);
            canvas.drawText("客户 " + kh + "", 25, 210, paint);
            canvas.drawText(""+number + "  " + user, 25, 240, paint);
            paint.setTextSize(22);
            canvas.save();
            canvas.restore();
            saveBitmap(result);
            return result;
        }


        public static Bitmap qualitysampling(String number,String name,String specification,String steel,String weight,String kh,String pcd,String qd,String zinc) {
            int picWidth=380;//生成图片的宽度
            int picHeight=280;//生成图片的高度
            int titleTextSize=24;
            int textColor=Color.BLACK;
            int qrWidth=180;
            int qrHeight=180;
            int paddingTop=80;

            //最终生成的图片
            Bitmap result = Bitmap.createBitmap(picWidth, picHeight, Bitmap.Config.ARGB_8888);

            Paint paint = new Paint();
            paint.setColor(Color.WHITE);
            Canvas canvas = new Canvas(result);

            //先画一整块白色矩形块
            canvas.drawRect(0, 0, picWidth, picHeight, paint);

            //        canvas.rotate(-90, 260, 260);

            //画白色矩形块

            paint.setColor(textColor);
            paint.setTextSize(titleTextSize);
            paint.setFakeBoldText(true);

            //画二维码
            Bitmap bitmap = BitmapUtils.encode2dAsBitmap(number, BarcodeFormat.QR_CODE, qrWidth, qrHeight);

            canvas.drawBitmap(bitmap, 0, -25, paint);

            //画title文字

            canvas.drawText("名称 " + name, 160, 30, paint);
            canvas.drawText("规格  " + specification + " mm", 160, 60, paint);
            canvas.drawText("钢号  " + steel + " ", 160, 90, paint);
            canvas.drawText("净重  " + weight +" T", 160, 120, paint);
            paint.setTextSize(22);
            canvas.drawText("排产单号：" + pcd + "", 25, 180, paint);
            canvas.drawText("" + number + "", 25, 240, paint);
            //canvas.drawText(""+number, 25, 240, paint);
            paint.setTextSize(22);
            canvas.save();
            canvas.restore();
            saveBitmap(result);
            return result;
        }


        public static Bitmap wireProduct(String number,String name,String specification,String steel,String weight,String zinc,String time,String qd,String zincBZ) {
            int picWidth = 580;//生成图片的宽度
            int picHeight = 310;//生成图片的高度
            int titleTextSize = 27;
            int textColor = Color.BLACK;
            int qrWidth = 250;
            int qrHeight = 250;

            //最终生成的图片
            Bitmap result = Bitmap.createBitmap(picWidth, picHeight, Bitmap.Config.ARGB_8888);

            Paint paint = new Paint();
            paint.setColor(Color.WHITE);
            Canvas canvas = new Canvas(result);

            //先画一整块白色矩形块
            canvas.drawRect(0, 0, picWidth, picHeight, paint);

            //        canvas.rotate(-90, 260, 260);

            //画白色矩形块

            paint.setColor(textColor);
            paint.setTextSize(titleTextSize);
            paint.setFakeBoldText(true);

            //画二维码
            Bitmap bitmap = BitmapUtils.encode2dAsBitmap(number, BarcodeFormat.QR_CODE, qrWidth, qrHeight);

            canvas.drawBitmap(bitmap, 0, -25, paint);

            //画title文字

            canvas.drawText("品名:  " + name, 220, 30, paint);
            canvas.drawText("规格:  " + specification + " mm", 220, 75, paint);
            canvas.drawText("钢号:  " + steel + "", 220, 120, paint);
            canvas.drawText("重量:  " + weight + " T", 220, 165, paint);
            canvas.drawText("抗拉强度:  " + qd +" MPa", 220, 210, paint);
            canvas.drawText("锌层:  " + zincBZ +" g/㎡", 220, 260, paint);
            canvas.drawText(""+ time + "", 25, 260, paint);
            canvas.drawText("编号："+ number, 25, 305, paint);
            canvas.save();
            canvas.restore();
            saveBitmap(result);
            result = adjustPhotoRotation(result, 90);
            return result;
        }


        public static Bitmap steelStrandProduct(String number,String name,String specification,String steel,String weight,String time,String qd) {
            int picWidth = 580;//生成图片的宽度
            int picHeight = 310;//生成图片的高度
            int titleTextSize = 27;
            int textColor = Color.BLACK;
            int qrWidth = 250;
            int qrHeight = 250;

            //最终生成的图片
            Bitmap result = Bitmap.createBitmap(picWidth, picHeight, Bitmap.Config.ARGB_8888);

            Paint paint = new Paint();
            paint.setColor(Color.WHITE);
            Canvas canvas = new Canvas(result);

            //先画一整块白色矩形块
            canvas.drawRect(0, 0, picWidth, picHeight, paint);

            //        canvas.rotate(-90, 260, 260);

            //画白色矩形块

            paint.setColor(textColor);
            paint.setTextSize(titleTextSize);
            paint.setFakeBoldText(true);

            //画二维码
            Bitmap bitmap = BitmapUtils.encode2dAsBitmap(number, BarcodeFormat.QR_CODE, qrWidth, qrHeight);

            canvas.drawBitmap(bitmap, 0, -25, paint);

            //画title文字

            canvas.drawText("品名:  " + "预应力钢绞线", 220, 30, paint);
            canvas.drawText("规格:  " + specification + " mm", 220, 75, paint);
            canvas.drawText("钢号:  " + steel + "", 220, 120, paint);
            canvas.drawText("重量:  " + weight + " T", 220, 165, paint);
            canvas.drawText("抗拉强度:  " + qd +" MPa", 220, 210, paint);
            canvas.drawText(""+ time + "", 25, 260, paint);
            canvas.drawText("编号："+ number, 25, 305, paint);
            canvas.save();
            canvas.restore();
            saveBitmap(result);
            result = adjustPhotoRotation(result, 90);
            return result;
        }


        public static Bitmap accessorypurchaseinorder(String code,String name,String specification,String weight,String batch) {
            int picWidth=350;//生成图片的宽度
            int picHeight=280;//生成图片的高度
            int titleTextSize=22;
            int textColor=Color.BLACK;
            int qrWidth=130;
            int qrHeight=130;
            int paddingTop=40;

            //最终生成的图片
            Bitmap result=Bitmap.createBitmap (picWidth, picHeight, Bitmap.Config.ARGB_8888);

            Paint paint=new Paint ();
            paint.setColor (Color.WHITE);
            Canvas canvas=new Canvas (result);

            //先画一整块白色矩形块
            canvas.drawRect (0, 0, picWidth, picHeight, paint);

            //画title文字
            paint.setColor (textColor);
            paint.setTextSize (titleTextSize);
            paint.setFakeBoldText(true);
            canvas.drawText (""+code, 165, 70, paint);
            canvas.drawText (""+name, 165, 120, paint);
            canvas.drawText (""+weight+"kg", 165, 170, paint);
            canvas.drawText (batch, 0, 190, paint);
            canvas.drawText (specification, 0, 230, paint);

            //画白色矩形块
            int qrTop=paddingTop;//二维码的顶部高度

            //画二维码
            Hashtable<EncodeHintType, Object> hints=new Hashtable<> ();
            hints.put (EncodeHintType.ERROR_CORRECTION, ErrorCorrectionLevel.H);
            hints.put (EncodeHintType.CHARACTER_SET, CHARSET);
            hints.put (EncodeHintType.MARGIN, 0);
            BitMatrix bitMatrix;
            Bitmap image=null;
            try {
                bitMatrix=new MultiFormatWriter ().encode (batch, BarcodeFormat.QR_CODE, qrWidth, qrHeight, hints);
                int width=bitMatrix.getWidth ();
                int height=bitMatrix.getHeight ();
                image=Bitmap.createBitmap (width, height, Bitmap.Config.ARGB_8888);
                for (int x=0; x < width; x++) {
                    for (int y=0; y < height; y++) {
                        image.setPixel (x, y, bitMatrix.get (x, y) ? 0xFF000000 : 0xFFFFFFFF);
                    }
                }
            } catch (Exception e) {
                e.printStackTrace ();
            }

            paint.setColor (Color.BLACK);
            canvas.drawBitmap (image, 0, qrTop, paint);
            canvas.save ();
            canvas.restore ();
            return result;
        }

        public static Bitmap comeprocessinorder(String qrcode,String vendor,String specification,String weight,String customer, String processType) {
                int picWidth=350;//生成图片的宽度
                int picHeight=280;//生成图片的高度
                int titleTextSize=25;
                int textColor=Color.BLACK;
                int qrWidth=150;
                int qrHeight=150;
                int paddingTop=40;

                //最终生成的图片
                Bitmap result=Bitmap.createBitmap (picWidth, picHeight, Bitmap.Config.ARGB_8888);

                Paint paint=new Paint ();
                paint.setColor (Color.WHITE);
                Canvas canvas=new Canvas (result);

                //先画一整块白色矩形块
                canvas.drawRect (0, 0, picWidth, picHeight, paint);

                //画title文字
                paint.setColor (textColor);
                paint.setTextSize (titleTextSize);
                paint.setFakeBoldText(true);
                canvas.drawText ("厂家: "+vendor, 165, 60, paint);
                canvas.drawText ("规格: "+specification, 165, 95, paint);
                canvas.drawText ("重量: "+weight+"kg", 165, 130, paint);
                canvas.drawText ("客户: "+customer+"", 165, 165, paint);
                canvas.drawText (""+processType+"", 165, 200, paint);
                canvas.drawText (qrcode, 0, 240, paint);

                //画白色矩形块
                int qrTop=paddingTop;//二维码的顶部高度

                //画二维码
                Hashtable<EncodeHintType, Object> hints=new Hashtable<> ();
                hints.put (EncodeHintType.ERROR_CORRECTION, ErrorCorrectionLevel.H);
                hints.put (EncodeHintType.CHARACTER_SET, CHARSET);
                hints.put (EncodeHintType.MARGIN, 0);
                BitMatrix bitMatrix;
                Bitmap image=null;
                try {
                    bitMatrix=new MultiFormatWriter ().encode (qrcode, BarcodeFormat.QR_CODE, qrWidth, qrHeight, hints);
                    int width=bitMatrix.getWidth ();
                    int height=bitMatrix.getHeight ();
                    image=Bitmap.createBitmap (width, height, Bitmap.Config.ARGB_8888);
                    for (int x=0; x < width; x++) {
                        for (int y=0; y < height; y++) {
                            image.setPixel (x, y, bitMatrix.get (x, y) ? 0xFF000000 : 0xFFFFFFFF);
                        }
                    }
                } catch (Exception e) {
                    e.printStackTrace ();
                }

                paint.setColor (Color.BLACK);
                canvas.drawBitmap (image, 0, qrTop, paint);
                canvas.save ();
                canvas.restore ();
                return result;
            }

        public static Bitmap initSilkwarehouse(String qrcode,String vendor,String specification,String weight) {
                    int picWidth=350;//生成图片的宽度
                    int picHeight=280;//生成图片的高度
                    int titleTextSize=25;
                    int textColor=Color.BLACK;
                    int qrWidth=150;
                    int qrHeight=150;
                    int paddingTop=40;

                    //最终生成的图片
                    Bitmap result=Bitmap.createBitmap (picWidth, picHeight, Bitmap.Config.ARGB_8888);

                    Paint paint=new Paint ();
                    paint.setColor (Color.WHITE);
                    Canvas canvas=new Canvas (result);

                    //先画一整块白色矩形块
                    canvas.drawRect (0, 0, picWidth, picHeight, paint);

                    //画title文字
                    paint.setColor (textColor);
                    paint.setTextSize (titleTextSize);
                    paint.setFakeBoldText(true);
                    canvas.drawText ("厂家: "+vendor, 165, 70, paint);
                    canvas.drawText ("规格: "+specification, 165, 120, paint);
                    canvas.drawText ("净重: "+weight+"kg", 165, 170, paint);
                    canvas.drawText (qrcode, 0, 240, paint);

                    //画白色矩形块
                    int qrTop=paddingTop;//二维码的顶部高度

                    //画二维码
                    Hashtable<EncodeHintType, Object> hints=new Hashtable<> ();
                    hints.put (EncodeHintType.ERROR_CORRECTION, ErrorCorrectionLevel.H);
                    hints.put (EncodeHintType.CHARACTER_SET, CHARSET);
                    hints.put (EncodeHintType.MARGIN, 0);
                    BitMatrix bitMatrix;
                    Bitmap image=null;
                    try {
                        bitMatrix=new MultiFormatWriter ().encode (qrcode, BarcodeFormat.QR_CODE, qrWidth, qrHeight, hints);
                        int width=bitMatrix.getWidth ();
                        int height=bitMatrix.getHeight ();
                        image=Bitmap.createBitmap (width, height, Bitmap.Config.ARGB_8888);
                        for (int x=0; x < width; x++) {
                            for (int y=0; y < height; y++) {
                                image.setPixel (x, y, bitMatrix.get (x, y) ? 0xFF000000 : 0xFFFFFFFF);
                            }
                        }
                    } catch (Exception e) {
                        e.printStackTrace ();
                    }

                    paint.setColor (Color.BLACK);
                    canvas.drawBitmap (image, 0, qrTop, paint);
                    canvas.save ();
                    canvas.restore ();
                    return result;
                }

        public static Bitmap returnorder(String qrcode,String vendor,String specification,String weight,String workplanNumber) {
                    int picWidth=350;//生成图片的宽度
                    int picHeight=280;//生成图片的高度
                    int titleTextSize=25;
                    int textColor=Color.BLACK;
                    int qrWidth=150;
                    int qrHeight=150;
                    int paddingTop=40;

                    //最终生成的图片
                    Bitmap result=Bitmap.createBitmap (picWidth, picHeight, Bitmap.Config.ARGB_8888);

                    Paint paint=new Paint ();
                    paint.setColor (Color.WHITE);
                    Canvas canvas=new Canvas (result);

                    //先画一整块白色矩形块
                    canvas.drawRect (0, 0, picWidth, picHeight, paint);

                    //画title文字
                    paint.setColor (textColor);
                    paint.setTextSize (titleTextSize);
                    paint.setFakeBoldText(true);
                    //canvas.drawText ("类型: "+vendor, 165, 50, paint);
                    canvas.drawText ("规格: "+specification, 165, 100, paint);
                    canvas.drawText ("重量: "+weight+"kg", 165, 150, paint);
                    //canvas.drawText ("排产单: "+workplanNumber+"", 165, 200, paint);
                    canvas.drawText (qrcode, 0, 240, paint);

                    //画白色矩形块
                    int qrTop=paddingTop;//二维码的顶部高度

                    //画二维码
                    Hashtable<EncodeHintType, Object> hints=new Hashtable<> ();
                    hints.put (EncodeHintType.ERROR_CORRECTION, ErrorCorrectionLevel.H);
                    hints.put (EncodeHintType.CHARACTER_SET, CHARSET);
                    hints.put (EncodeHintType.MARGIN, 0);
                    BitMatrix bitMatrix;
                    Bitmap image=null;
                    try {
                        bitMatrix=new MultiFormatWriter ().encode (qrcode, BarcodeFormat.QR_CODE, qrWidth, qrHeight, hints);
                        int width=bitMatrix.getWidth ();
                        int height=bitMatrix.getHeight ();
                        image=Bitmap.createBitmap (width, height, Bitmap.Config.ARGB_8888);
                        for (int x=0; x < width; x++) {
                            for (int y=0; y < height; y++) {
                                image.setPixel (x, y, bitMatrix.get (x, y) ? 0xFF000000 : 0xFFFFFFFF);
                            }
                        }
                    } catch (Exception e) {
                        e.printStackTrace ();
                    }

                    paint.setColor (Color.BLACK);
                    canvas.drawBitmap (image, 0, qrTop, paint);
                    canvas.save ();
                    canvas.restore ();
                    return result;
                }

        public static Bitmap initProductwarehouses(String number,String specification,String weight,String workplanNumber) {
                    int picWidth=350;//生成图片的宽度
                    int picHeight=280;//生成图片的高度
                    int titleTextSize=25;
                    int textColor=Color.BLACK;
                    int qrWidth=150;
                    int qrHeight=150;
                    int paddingTop=40;

                    //最终生成的图片
                    Bitmap result=Bitmap.createBitmap (picWidth, picHeight, Bitmap.Config.ARGB_8888);

                    Paint paint=new Paint ();
                    paint.setColor (Color.WHITE);
                    Canvas canvas=new Canvas (result);

                    //先画一整块白色矩形块
                    canvas.drawRect (0, 0, picWidth, picHeight, paint);

                    //画title文字
                    paint.setColor (textColor);
                    paint.setTextSize (titleTextSize);
                    paint.setFakeBoldText(true);
                    canvas.drawText ("排产单: "+workplanNumber, 165, 80, paint);
                    canvas.drawText ("净重: "+weight, 165, 130, paint);
                    canvas.drawText ("规格: "+specification, 50, 250, paint);
                    paint.setTextSize (20);
                    canvas.drawText (number, 0, 220, paint);

                    //画白色矩形块
                    int qrTop=paddingTop;//二维码的顶部高度

                    //画二维码
                    Hashtable<EncodeHintType, Object> hints=new Hashtable<> ();
                    hints.put (EncodeHintType.ERROR_CORRECTION, ErrorCorrectionLevel.H);
                    hints.put (EncodeHintType.CHARACTER_SET, CHARSET);
                    hints.put (EncodeHintType.MARGIN, 0);
                    BitMatrix bitMatrix;
                    Bitmap image=null;
                    try {
                        bitMatrix=new MultiFormatWriter ().encode (number, BarcodeFormat.QR_CODE, qrWidth, qrHeight, hints);
                        int width=bitMatrix.getWidth ();
                        int height=bitMatrix.getHeight ();
                        image=Bitmap.createBitmap (width, height, Bitmap.Config.ARGB_8888);
                        for (int x=0; x < width; x++) {
                            for (int y=0; y < height; y++) {
                                image.setPixel (x, y, bitMatrix.get (x, y) ? 0xFF000000 : 0xFFFFFFFF);
                            }
                        }
                    } catch (Exception e) {
                        e.printStackTrace ();
                    }

                    paint.setColor (Color.BLACK);
                    canvas.drawBitmap (image, 0, qrTop, paint);
                    canvas.save ();
                    canvas.restore ();
                    return result;
                }

        public static Bitmap wirerodcollectoutorder(String number,String specification,String amount,String machine) {
                    int picWidth=350;//生成图片的宽度
                    int picHeight=280;//生成图片的高度
                    int titleTextSize=25;
                    int textColor=Color.BLACK;
                    //最终生成的图片
                    Bitmap result=Bitmap.createBitmap (picWidth, picHeight, Bitmap.Config.ARGB_8888);

                    Paint paint=new Paint ();
                    paint.setColor (Color.WHITE);
                    Canvas canvas=new Canvas (result);

                    //先画一整块白色矩形块
                    canvas.drawRect (0, 0, picWidth, picHeight, paint);

                    //画title文字
                    paint.setColor (textColor);
                    paint.setTextSize (titleTextSize);
                    paint.setFakeBoldText(true);
                    canvas.drawText ("排产单: "+number, 0, 50, paint);
                    canvas.drawText ("规格: "+specification, 0, 110, paint);
                    canvas.drawText ("重量: "+amount, 0, 170, paint);
                    canvas.drawText ("机台: "+machine, 0, 230, paint);
                    canvas.save ();
                    canvas.restore ();
                    return result;
        }


        public static Bitmap initRopeWirewarehouse(String number,String dcbz,String pm,String gg,String qd,String mc,String mz,String pz,String jz,String czg,String rq,String kh,String xd,String gh,String pcd,String axleLength) {
                      int picWidth=380;//生成图片的宽度
                      int picHeight=280;//生成图片的高度
                      int titleTextSize=24;
                      int textColor=Color.BLACK;
                      int qrWidth=180;
                      int qrHeight=180;
                      int paddingTop=80;

                                       //最终生成的图片
                      Bitmap result = Bitmap.createBitmap(picWidth, picHeight, Bitmap.Config.ARGB_8888);

                      Paint paint = new Paint();
                      paint.setColor(Color.WHITE);
                      Canvas canvas = new Canvas(result);

                                       //先画一整块白色矩形块
                      canvas.drawRect(0, 0, picWidth, picHeight, paint);

                                       //        canvas.rotate(-90, 260, 260);

                                       //画白色矩形块

                      paint.setColor(textColor);
                      paint.setTextSize(titleTextSize);
                      paint.setFakeBoldText(true);

                                       //画二维码
                      Bitmap bitmap = BitmapUtils.encode2dAsBitmap(number, BarcodeFormat.QR_CODE, qrWidth, qrHeight);

                      canvas.drawBitmap(bitmap, 0, -25, paint);

                                       //画title文字

                      canvas.drawText("客户 " + kh, 160, 30, paint);
                      canvas.drawText("名称  " + pm, 160, 60, paint);
                      canvas.drawText("规格  " + gg, 160, 90, paint);
                      canvas.drawText("长度  " + axleLength +" m", 160, 120, paint);
                      canvas.drawText("实际  " + mc +" m", 160, 150, paint);
                      //canvas.drawText("净重  " + jz +" kg", 160, 180, paint);
                      canvas.drawText(czg + " " + rq + "", 25, 180, paint);
                      canvas.drawText("排产单 " + pcd + "", 25, 210, paint);
                      paint.setTextSize(22);
                      canvas.drawText(""+number, 25, 240, paint);
                      paint.setTextSize(22);
                      canvas.save();
                      canvas.restore();
                      saveBitmap(result);
                      return result;
                }

        public static Bitmap initTwistWirewarehouse(String number,String mc,String name,String specification,String jg,String zj,String nx,String bm,String qd,String ty,String date,String user,String length,String sgg,String pcd,String isShort) {
            int picWidth = 580;//生成图片的宽度
            int picHeight = 310;//生成图片的高度
            int titleTextSize = 27;
            int textColor = Color.BLACK;
            int qrWidth = 250;
            int qrHeight = 250;

            //最终生成的图片
            Bitmap result = Bitmap.createBitmap(picWidth, picHeight, Bitmap.Config.ARGB_8888);

            Paint paint = new Paint();
            paint.setColor(Color.WHITE);
            Canvas canvas = new Canvas(result);

            //先画一整块白色矩形块
            canvas.drawRect(0, 0, picWidth, picHeight, paint);

            //        canvas.rotate(-90, 260, 260);

            //画白色矩形块

            paint.setColor(textColor);
            paint.setTextSize(titleTextSize);
            paint.setFakeBoldText(true);

            //画二维码
            Bitmap bitmap = BitmapUtils.encode2dAsBitmap(number, BarcodeFormat.QR_CODE, qrWidth, qrHeight);

            canvas.drawBitmap(bitmap, 0, -25, paint);

            //画title文字

            canvas.drawText("品名:  " + name, 220, 25, paint);
            canvas.drawText("规格:  " + jg + "-" + zj, 220, 60, paint);
            canvas.drawText("钢丝绳规格:  " + sgg + "", 220, 95, paint);
            canvas.drawText("强度:  " + qd + " MPa", 220, 130, paint);
            //canvas.drawText("表面:  " + bm +" ", 420, 130, paint);
            canvas.drawText("长度:  " + mc +" m", 220, 165, paint);
            canvas.drawText("实际:  " + length +" m", 410, 165, paint);
            canvas.drawText("涂油:  " + ty + "", 220, 200, paint);
            canvas.drawText("捻向:  " + nx +"", 420, 200, paint);
            canvas.drawText("日期:  " + date + "  " + isShort, 220, 235, paint);
            canvas.drawText("排产单:  " + pcd + "", 25, 270, paint);
            canvas.drawText("工人:  " + user + "", 410, 270, paint);
            canvas.drawText("编号："+ number, 25, 305, paint);
            //canvas.drawText("排产单："+ pcd, 25, 335, paint);
            canvas.save();
            canvas.restore();
            saveBitmap(result);
            result = adjustPhotoRotation(result, 90);
            return result;
        }

        public static Bitmap initUniteWirewarehouse(String number,String mc,String name,String specification,String jg,String zj,String nx,String bm,String qd,String ty,String date,String user,String pcd,String sjmc,String isShort,String ddxx) {
            int picWidth = 580;//生成图片的宽度
            int picHeight = 310;//生成图片的高度
            int titleTextSize = 27;
            int textColor = Color.BLACK;
            int qrWidth = 250;
            int qrHeight = 250;

            //最终生成的图片
            Bitmap result = Bitmap.createBitmap(picWidth, picHeight, Bitmap.Config.ARGB_8888);

            Paint paint = new Paint();
            paint.setColor(Color.WHITE);
            Canvas canvas = new Canvas(result);

            //先画一整块白色矩形块
            canvas.drawRect(0, 0, picWidth, picHeight, paint);

            //        canvas.rotate(-90, 260, 260);

            //画白色矩形块

            paint.setColor(textColor);
            paint.setTextSize(titleTextSize);
            paint.setFakeBoldText(true);

            //画二维码
            Bitmap bitmap = BitmapUtils.encode2dAsBitmap(number, BarcodeFormat.QR_CODE, qrWidth, qrHeight);

            canvas.drawBitmap(bitmap, 0, -25, paint);

            //画title文字

            canvas.drawText("品名:  " + name, 220, 25, paint);
            canvas.drawText("规格:  " + jg + "-" + zj, 220, 60, paint);
            canvas.drawText("表面:  " + bm + "", 220, 95, paint);
            canvas.drawText("断点:  " + ddxx +"", 370, 95, paint);
            canvas.drawText("强度:  " + qd + " MPa", 220, 130, paint);
            canvas.drawText("长度:  " + mc +" m", 220, 165, paint);
            canvas.drawText("捻向:  " + nx +"", 420, 165, paint);
            canvas.drawText("涂油:  " + ty + "", 220, 200, paint);
            canvas.drawText("实际:  " + sjmc + " m", 410, 200, paint);
            canvas.drawText("日期:  " + date + "  " + isShort, 220, 235, paint);
            canvas.drawText("排产单:  " + pcd + "", 25, 270, paint);
            canvas.drawText("工人:  " + user + "", 410, 270, paint);
            canvas.drawText("编号："+ number, 25, 305, paint);
            //canvas.drawText("排产单："+ pcd, 25, 335, paint);
            canvas.save();
            canvas.restore();
            saveBitmap(result);
            result = adjustPhotoRotation(result, 90);
            return result;
        }

        public static Bitmap initHDFCwarehouse(String number,String mc,String name,String specification,String jg,String zj,String nx,String bm,String qd,String ty,String date,String user,String machine,String mz,String pz,String jz,String ddxx) {
            int picWidth = 580;//生成图片的宽度
            int picHeight = 310;//生成图片的高度
            int titleTextSize = 27;
            int textColor = Color.BLACK;
            int qrWidth = 250;
            int qrHeight = 250;

            //最终生成的图片
            Bitmap result = Bitmap.createBitmap(picWidth, picHeight, Bitmap.Config.ARGB_8888);

            Paint paint = new Paint();
            paint.setColor(Color.WHITE);
            Canvas canvas = new Canvas(result);

            //先画一整块白色矩形块
            canvas.drawRect(0, 0, picWidth, picHeight, paint);

            //        canvas.rotate(-90, 260, 260);

            //画白色矩形块

            paint.setColor(textColor);
            paint.setTextSize(titleTextSize);
            paint.setFakeBoldText(true);

            //画二维码
            Bitmap bitmap = BitmapUtils.encode2dAsBitmap(number, BarcodeFormat.QR_CODE, qrWidth, qrHeight);

            canvas.drawBitmap(bitmap, 0, -25, paint);

            //画title文字

            canvas.drawText("品名:  " + name, 220, 25, paint);
            canvas.drawText("规格:  " + jg + "-" + zj, 220, 60, paint);
            canvas.drawText("表面:  " + bm + "", 220, 95, paint);
            canvas.drawText("断点:  " + ddxx +"", 370, 95, paint);
            canvas.drawText("强度:  " + qd + " MPa", 220, 130, paint);
            canvas.drawText("长度:  " + mc +" m", 220, 165, paint);
            canvas.drawText("捻向:  " + nx +"", 420, 165, paint);
            canvas.drawText("涂油:  " + ty + "", 220, 200, paint);
            canvas.drawText("日期:  " + date + "", 220, 235, paint);
            canvas.drawText("工人:  " + user + "", 220, 270, paint);
            canvas.drawText("毛重："+ mz + " kg", 25, 235, paint);
            canvas.drawText("净重："+ jz + " kg", 25, 270, paint);
            canvas.drawText("编号："+ number, 25, 305, paint);
            canvas.save();
            canvas.restore();
            saveBitmap(result);
            result = adjustPhotoRotation(result, 90);
            return result;
        }

        public static Bitmap adjustPhotoRotation(Bitmap bm, final int orientationDegree) {

            Matrix m = new Matrix();
            m.setRotate(orientationDegree, (float) bm.getWidth() / 2, (float) bm.getHeight() / 2);
            try {
                Bitmap bm1 = Bitmap.createBitmap(bm, 0, 0, bm.getWidth(), bm.getHeight(), m, true);
                return bm1;
            } catch (Exception ex) {
                ex.printStackTrace();
            }
            return null;

        }

        public static void saveBitmap(Bitmap bitmap) {
            if (false == isSave) {
                return;
            }
            isSave = false;
            String savePath;
            File filePic;
            savePath = Environment.getExternalStorageDirectory() + "/1.jpg";
            try {
                filePic = new File(savePath);
                if (!filePic.exists()) {
                    filePic.getParentFile().mkdirs();
                    filePic.createNewFile();
                }
                FileOutputStream fos = new FileOutputStream(filePic);
                bitmap.compress(Bitmap.CompressFormat.JPEG, 100, fos);
                fos.flush();
                fos.close();
            } catch (IOException e) {
                return;
            }

        }

}
